package com.ls.socketio.repository;

import com.ls.socketio.bean.RoomBoxInfo;
import com.ls.socketio.bean.RoomInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author liShan
 * @date 2019/9/3 17:42
 */
public interface RoomRepository extends JpaRepository<RoomInfo, Long> {

    /**
     * 查询房间的id，根据房间的位置
     * @param boxInfo  房间的位置
     * @return 房间的id
     */
    @Query(nativeQuery = true,
            value = "SELECT room.room_id FROM room " +
                    "RIGHT JOIN layer ON room.layer_id = layer.layer_id AND layer.layer_num = :#{#boxInfo.layerNum} \n" +
                    "RIGHT JOIN build ON layer.build_id = build.build_id AND build.hotel_id = :#{#boxInfo.hotelNum} AND build.build_num = :#{#boxInfo.buildingNum} " +
                    "WHERE room.room_num = :#{#boxInfo.roomNum}")
    Long findRoomId(@Param("boxInfo") RoomBoxInfo boxInfo);

    /**
     * 根据楼层id房间
     * @param layerId 楼层id
     * @return 房间的集合
     */
    @Query(nativeQuery = true,
            value = "select * from room where room.layer_id = :layerId LIMIT 0, 20")
    List<RoomInfo> findRoomByLayerId(@Param("layerId") Long layerId);

}
